<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html 
     PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
     "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
  <title>Class: Paperclip::Attachment</title>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  <meta http-equiv="Content-Script-Type" content="text/javascript" />
  <link rel="stylesheet" href="../.././rdoc-style.css" type="text/css" media="screen" />
  <script type="text/javascript">
  // <![CDATA[

  function popupCode( url ) {
    window.open(url, "Code", "resizable=yes,scrollbars=yes,toolbar=no,status=no,height=150,width=400")
  }

  function toggleCode( id ) {
    if ( document.getElementById )
      elem = document.getElementById( id );
    else if ( document.all )
      elem = eval( "document.all." + id );
    else
      return false;

    elemStyle = elem.style;
    
    if ( elemStyle.display != "block" ) {
      elemStyle.display = "block"
    } else {
      elemStyle.display = "none"
    }

    return true;
  }
  
  // Make codeblocks hidden by default
  document.writeln( "<style type=\"text/css\">div.method-source-code { display: none }</style>" )
  
  // ]]>
  </script>

</head>
<body>



    <div id="classHeader">
        <table class="header-table">
        <tr class="top-aligned-row">
          <td><strong>Class</strong></td>
          <td class="class-name-in-header">Paperclip::Attachment</td>
        </tr>
        <tr class="top-aligned-row">
            <td><strong>In:</strong></td>
            <td>
                <a href="../../files/vendor/plugins/paperclip/lib/paperclip/attachment_rb.html">
                vendor/plugins/paperclip/lib/paperclip/attachment.rb
                </a>
        <br />
            </td>
        </tr>

        <tr class="top-aligned-row">
            <td><strong>Parent:</strong></td>
            <td>
                Object
            </td>
        </tr>
        </table>
    </div>
  <!-- banner header -->

  <div id="bodyContent">



  <div id="contextContent">

    <div id="description">
      <p>
The <a href="Attachment.html">Attachment</a> class manages the files for a
given attachment. It saves when the model saves, deletes when the model is
destroyed, and processes the file upon assignment.
</p>

    </div>


   </div>

    <div id="method-list">
      <h3 class="section-bar">Methods</h3>

      <div class="name-list">
      <a href="#M000125">assign</a>&nbsp;&nbsp;
      <a href="#M000132">clear</a>&nbsp;&nbsp;
      <a href="#M000136">content_type</a>&nbsp;&nbsp;
      <a href="#M000121">default_options</a>&nbsp;&nbsp;
      <a href="#M000133">destroy</a>&nbsp;&nbsp;
      <a href="#M000130">dirty?</a>&nbsp;&nbsp;
      <a href="#M000129">errors</a>&nbsp;&nbsp;
      <a href="#M000140">file?</a>&nbsp;&nbsp;
      <a href="#M000142">instance_read</a>&nbsp;&nbsp;
      <a href="#M000141">instance_write</a>&nbsp;&nbsp;
      <a href="#M000138">interpolations</a>&nbsp;&nbsp;
      <a href="#M000122">new</a>&nbsp;&nbsp;
      <a href="#M000134">original_filename</a>&nbsp;&nbsp;
      <a href="#M000127">path</a>&nbsp;&nbsp;
      <a href="#M000124">processors</a>&nbsp;&nbsp;
      <a href="#M000139">reprocess!</a>&nbsp;&nbsp;
      <a href="#M000131">save</a>&nbsp;&nbsp;
      <a href="#M000135">size</a>&nbsp;&nbsp;
      <a href="#M000123">styles</a>&nbsp;&nbsp;
      <a href="#M000128">to_s</a>&nbsp;&nbsp;
      <a href="#M000137">updated_at</a>&nbsp;&nbsp;
      <a href="#M000126">url</a>&nbsp;&nbsp;
      </div>
    </div>

  </div>


    <!-- if includes -->

    <div id="section">





    <div id="attribute-list">
      <h3 class="section-bar">Attributes</h3>

      <div class="name-list">
        <table>
        <tr class="top-aligned-row context-row">
          <td class="context-item-name">convert_options</td>
          <td class="context-item-value">&nbsp;[R]&nbsp;</td>
          <td class="context-item-desc"></td>
        </tr>
        <tr class="top-aligned-row context-row">
          <td class="context-item-name">default_style</td>
          <td class="context-item-value">&nbsp;[R]&nbsp;</td>
          <td class="context-item-desc"></td>
        </tr>
        <tr class="top-aligned-row context-row">
          <td class="context-item-name">instance</td>
          <td class="context-item-value">&nbsp;[R]&nbsp;</td>
          <td class="context-item-desc"></td>
        </tr>
        <tr class="top-aligned-row context-row">
          <td class="context-item-name">name</td>
          <td class="context-item-value">&nbsp;[R]&nbsp;</td>
          <td class="context-item-desc"></td>
        </tr>
        <tr class="top-aligned-row context-row">
          <td class="context-item-name">options</td>
          <td class="context-item-value">&nbsp;[R]&nbsp;</td>
          <td class="context-item-desc"></td>
        </tr>
        <tr class="top-aligned-row context-row">
          <td class="context-item-name">queued_for_write</td>
          <td class="context-item-value">&nbsp;[R]&nbsp;</td>
          <td class="context-item-desc"></td>
        </tr>
        <tr class="top-aligned-row context-row">
          <td class="context-item-name">whiny</td>
          <td class="context-item-value">&nbsp;[R]&nbsp;</td>
          <td class="context-item-desc"></td>
        </tr>
        </table>
      </div>
    </div>
      


    <!-- if method_list -->
    <div id="methods">
      <h3 class="section-bar">Public Class methods</h3>

      <div id="method-M000121" class="method-detail">
        <a name="M000121"></a>

        <div class="method-heading">
          <a href="#M000121" class="method-signature">
          <span class="method-name">default_options</span><span class="method-args">()</span>
          </a>
        </div>
      
        <div class="method-description">
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000121-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000121-source">
<pre>
    <span class="ruby-comment cmt"># File vendor/plugins/paperclip/lib/paperclip/attachment.rb, line 8</span>
 8:     <span class="ruby-keyword kw">def</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">default_options</span>
 9:       <span class="ruby-ivar">@default_options</span> <span class="ruby-operator">||=</span> {
10:         <span class="ruby-identifier">:url</span>               =<span class="ruby-operator">&gt;</span> <span class="ruby-value str">&quot;/system/:attachment/:id/:style/:filename&quot;</span>,
11:         <span class="ruby-identifier">:path</span>              =<span class="ruby-operator">&gt;</span> <span class="ruby-value str">&quot;:rails_root/public:url&quot;</span>,
12:         <span class="ruby-identifier">:styles</span>            =<span class="ruby-operator">&gt;</span> {},
13:         <span class="ruby-identifier">:processors</span>        =<span class="ruby-operator">&gt;</span> [<span class="ruby-identifier">:thumbnail</span>],
14:         <span class="ruby-identifier">:convert_options</span>   =<span class="ruby-operator">&gt;</span> {},
15:         <span class="ruby-identifier">:default_url</span>       =<span class="ruby-operator">&gt;</span> <span class="ruby-value str">&quot;/:attachment/:style/missing.png&quot;</span>,
16:         <span class="ruby-identifier">:default_style</span>     =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">:original</span>,
17:         <span class="ruby-identifier">:storage</span>           =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">:filesystem</span>,
18:         <span class="ruby-identifier">:whiny</span>             =<span class="ruby-operator">&gt;</span> <span class="ruby-constant">Paperclip</span>.<span class="ruby-identifier">options</span>[<span class="ruby-identifier">:whiny</span>] <span class="ruby-operator">||</span> <span class="ruby-constant">Paperclip</span>.<span class="ruby-identifier">options</span>[<span class="ruby-identifier">:whiny_thumbnails</span>]
19:       }
20:     <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000138" class="method-detail">
        <a name="M000138"></a>

        <div class="method-heading">
          <a href="#M000138" class="method-signature">
          <span class="method-name">interpolations</span><span class="method-args">()</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Paths and URLs can have a number of variables interpolated into them to
vary the storage location based on name, id, style, class, etc. This method
is a deprecated access into supplying and retrieving these <a
href="Attachment.html#M000138">interpolations</a>. Future access should use
either <a href="../Paperclip.html#M000007">Paperclip.interpolates</a> or
extend the <a href="Interpolations.html">Paperclip::Interpolations</a>
module directly.
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000138-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000138-source">
<pre>
     <span class="ruby-comment cmt"># File vendor/plugins/paperclip/lib/paperclip/attachment.rb, line 195</span>
195:     <span class="ruby-keyword kw">def</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">interpolations</span>
196:       <span class="ruby-identifier">warn</span>(<span class="ruby-value str">'[DEPRECATION] Paperclip::Attachment.interpolations is deprecated '</span> <span class="ruby-operator">+</span>
197:            <span class="ruby-value str">'and will be removed from future versions. '</span> <span class="ruby-operator">+</span>
198:            <span class="ruby-value str">'Use Paperclip.interpolates instead'</span>)
199:       <span class="ruby-constant">Paperclip</span><span class="ruby-operator">::</span><span class="ruby-constant">Interpolations</span>
200:     <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000122" class="method-detail">
        <a name="M000122"></a>

        <div class="method-heading">
          <a href="#M000122" class="method-signature">
          <span class="method-name">new</span><span class="method-args">(name, instance, options = {})</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Creates an <a href="Attachment.html">Attachment</a> object. <tt>name</tt>
is the name of the attachment, <tt>instance</tt> is the ActiveRecord object
instance it&#8216;s attached to, and <tt>options</tt> is the same as the
hash passed to <tt>has_attached_file</tt>.
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000122-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000122-source">
<pre>
    <span class="ruby-comment cmt"># File vendor/plugins/paperclip/lib/paperclip/attachment.rb, line 27</span>
27:     <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">initialize</span> <span class="ruby-identifier">name</span>, <span class="ruby-identifier">instance</span>, <span class="ruby-identifier">options</span> = {}
28:       <span class="ruby-ivar">@name</span>              = <span class="ruby-identifier">name</span>
29:       <span class="ruby-ivar">@instance</span>          = <span class="ruby-identifier">instance</span>
30: 
31:       <span class="ruby-identifier">options</span> = <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">class</span>.<span class="ruby-identifier">default_options</span>.<span class="ruby-identifier">merge</span>(<span class="ruby-identifier">options</span>)
32: 
33:       <span class="ruby-ivar">@url</span>               = <span class="ruby-identifier">options</span>[<span class="ruby-identifier">:url</span>]
34:       <span class="ruby-ivar">@url</span>               = <span class="ruby-ivar">@url</span>.<span class="ruby-identifier">call</span>(<span class="ruby-keyword kw">self</span>) <span class="ruby-keyword kw">if</span> <span class="ruby-ivar">@url</span>.<span class="ruby-identifier">is_a?</span>(<span class="ruby-constant">Proc</span>)
35:       <span class="ruby-ivar">@path</span>              = <span class="ruby-identifier">options</span>[<span class="ruby-identifier">:path</span>]
36:       <span class="ruby-ivar">@path</span>              = <span class="ruby-ivar">@path</span>.<span class="ruby-identifier">call</span>(<span class="ruby-keyword kw">self</span>) <span class="ruby-keyword kw">if</span> <span class="ruby-ivar">@path</span>.<span class="ruby-identifier">is_a?</span>(<span class="ruby-constant">Proc</span>)
37:       <span class="ruby-ivar">@styles</span>            = <span class="ruby-identifier">options</span>[<span class="ruby-identifier">:styles</span>]
38:       <span class="ruby-ivar">@normalized_styles</span> = <span class="ruby-keyword kw">nil</span>
39:       <span class="ruby-ivar">@default_url</span>       = <span class="ruby-identifier">options</span>[<span class="ruby-identifier">:default_url</span>]
40:       <span class="ruby-ivar">@default_style</span>     = <span class="ruby-identifier">options</span>[<span class="ruby-identifier">:default_style</span>]
41:       <span class="ruby-ivar">@storage</span>           = <span class="ruby-identifier">options</span>[<span class="ruby-identifier">:storage</span>]
42:       <span class="ruby-ivar">@whiny</span>             = <span class="ruby-identifier">options</span>[<span class="ruby-identifier">:whiny_thumbnails</span>] <span class="ruby-operator">||</span> <span class="ruby-identifier">options</span>[<span class="ruby-identifier">:whiny</span>]
43:       <span class="ruby-ivar">@convert_options</span>   = <span class="ruby-identifier">options</span>[<span class="ruby-identifier">:convert_options</span>]
44:       <span class="ruby-ivar">@processors</span>        = <span class="ruby-identifier">options</span>[<span class="ruby-identifier">:processors</span>]
45:       <span class="ruby-ivar">@options</span>           = <span class="ruby-identifier">options</span>
46:       <span class="ruby-ivar">@queued_for_delete</span> = []
47:       <span class="ruby-ivar">@queued_for_write</span>  = {}
48:       <span class="ruby-ivar">@errors</span>            = {}
49:       <span class="ruby-ivar">@dirty</span>             = <span class="ruby-keyword kw">false</span>
50: 
51:       <span class="ruby-identifier">initialize_storage</span>
52:     <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <h3 class="section-bar">Public Instance methods</h3>

      <div id="method-M000125" class="method-detail">
        <a name="M000125"></a>

        <div class="method-heading">
          <a href="#M000125" class="method-signature">
          <span class="method-name">assign</span><span class="method-args">(uploaded_file)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
What gets called when you call instance.attachment = File. It clears <a
href="Attachment.html#M000129">errors</a>, assigns attributes, and
processes the file. It also queues up the previous file for deletion, to be
flushed away on <a href="Attachment.html#M000131">save</a> of its host. In
addition to form uploads, you can also <a
href="Attachment.html#M000125">assign</a> another <a
href="../Paperclip.html">Paperclip</a> attachment:
</p>
<pre>
  new_user.avatar = old_user.avatar
</pre>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000125-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000125-source">
<pre>
     <span class="ruby-comment cmt"># File vendor/plugins/paperclip/lib/paperclip/attachment.rb, line 74</span>
 74:     <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">assign</span> <span class="ruby-identifier">uploaded_file</span>
 75:       <span class="ruby-identifier">ensure_required_accessors!</span>
 76: 
 77:       <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">uploaded_file</span>.<span class="ruby-identifier">is_a?</span>(<span class="ruby-constant">Paperclip</span><span class="ruby-operator">::</span><span class="ruby-constant">Attachment</span>)
 78:         <span class="ruby-identifier">uploaded_file</span> = <span class="ruby-identifier">uploaded_file</span>.<span class="ruby-identifier">to_file</span>(<span class="ruby-identifier">:original</span>)
 79:         <span class="ruby-identifier">close_uploaded_file</span> = <span class="ruby-identifier">uploaded_file</span>.<span class="ruby-identifier">respond_to?</span>(<span class="ruby-identifier">:close</span>)
 80:       <span class="ruby-keyword kw">end</span>
 81: 
 82:       <span class="ruby-keyword kw">return</span> <span class="ruby-keyword kw">nil</span> <span class="ruby-keyword kw">unless</span> <span class="ruby-identifier">valid_assignment?</span>(<span class="ruby-identifier">uploaded_file</span>)
 83: 
 84:       <span class="ruby-identifier">uploaded_file</span>.<span class="ruby-identifier">binmode</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">uploaded_file</span>.<span class="ruby-identifier">respond_to?</span> <span class="ruby-identifier">:binmode</span>
 85:       <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">clear</span>
 86: 
 87:       <span class="ruby-keyword kw">return</span> <span class="ruby-keyword kw">nil</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">uploaded_file</span>.<span class="ruby-identifier">nil?</span>
 88: 
 89:       <span class="ruby-ivar">@queued_for_write</span>[<span class="ruby-identifier">:original</span>]   = <span class="ruby-identifier">uploaded_file</span>.<span class="ruby-identifier">to_tempfile</span>
 90:       <span class="ruby-identifier">instance_write</span>(<span class="ruby-identifier">:file_name</span>,       <span class="ruby-identifier">uploaded_file</span>.<span class="ruby-identifier">original_filename</span>.<span class="ruby-identifier">strip</span>.<span class="ruby-identifier">gsub</span>(<span class="ruby-regexp re">/[^A-Za-z\d\.\-_]+/</span>, <span class="ruby-value str">'_'</span>))
 91:       <span class="ruby-identifier">instance_write</span>(<span class="ruby-identifier">:content_type</span>,    <span class="ruby-identifier">uploaded_file</span>.<span class="ruby-identifier">content_type</span>.<span class="ruby-identifier">to_s</span>.<span class="ruby-identifier">strip</span>)
 92:       <span class="ruby-identifier">instance_write</span>(<span class="ruby-identifier">:file_size</span>,       <span class="ruby-identifier">uploaded_file</span>.<span class="ruby-identifier">size</span>.<span class="ruby-identifier">to_i</span>)
 93:       <span class="ruby-identifier">instance_write</span>(<span class="ruby-identifier">:updated_at</span>,      <span class="ruby-constant">Time</span>.<span class="ruby-identifier">now</span>)
 94: 
 95:       <span class="ruby-ivar">@dirty</span> = <span class="ruby-keyword kw">true</span>
 96: 
 97:       <span class="ruby-identifier">post_process</span>
 98:  
 99:       <span class="ruby-comment cmt"># Reset the file size if the original file was reprocessed.</span>
100:       <span class="ruby-identifier">instance_write</span>(<span class="ruby-identifier">:file_size</span>, <span class="ruby-ivar">@queued_for_write</span>[<span class="ruby-identifier">:original</span>].<span class="ruby-identifier">size</span>.<span class="ruby-identifier">to_i</span>)
101:     <span class="ruby-keyword kw">ensure</span>
102:       <span class="ruby-identifier">uploaded_file</span>.<span class="ruby-identifier">close</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">close_uploaded_file</span>
103:     <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000132" class="method-detail">
        <a name="M000132"></a>

        <div class="method-heading">
          <a href="#M000132" class="method-signature">
          <span class="method-name">clear</span><span class="method-args">()</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Clears out the attachment. Has the same effect as previously assigning nil
to the attachment. Does NOT <a href="Attachment.html#M000131">save</a>. If
you wish to <a href="Attachment.html#M000132">clear</a> AND <a
href="Attachment.html#M000131">save</a>, use <a
href="Attachment.html#M000133">destroy</a>.
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000132-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000132-source">
<pre>
     <span class="ruby-comment cmt"># File vendor/plugins/paperclip/lib/paperclip/attachment.rb, line 152</span>
152:     <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">clear</span>
153:       <span class="ruby-identifier">queue_existing_for_delete</span>
154:       <span class="ruby-ivar">@errors</span>            = {}
155:     <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000136" class="method-detail">
        <a name="M000136"></a>

        <div class="method-heading">
          <a href="#M000136" class="method-signature">
          <span class="method-name">content_type</span><span class="method-args">()</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Returns the <a href="Attachment.html#M000136">content_type</a> of the file
as originally assigned, and lives in the &lt;attachment&gt;_content_type
attribute of the model.
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000136-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000136-source">
<pre>
     <span class="ruby-comment cmt"># File vendor/plugins/paperclip/lib/paperclip/attachment.rb, line 179</span>
179:     <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">content_type</span>
180:       <span class="ruby-identifier">instance_read</span>(<span class="ruby-identifier">:content_type</span>)
181:     <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000133" class="method-detail">
        <a name="M000133"></a>

        <div class="method-heading">
          <a href="#M000133" class="method-signature">
          <span class="method-name">destroy</span><span class="method-args">()</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Destroys the attachment. Has the same effect as previously assigning nil to
the attachment *and saving*. This is permanent. If you wish to wipe out the
existing attachment but not <a href="Attachment.html#M000131">save</a>, use
<a href="Attachment.html#M000132">clear</a>.
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000133-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000133-source">
<pre>
     <span class="ruby-comment cmt"># File vendor/plugins/paperclip/lib/paperclip/attachment.rb, line 160</span>
160:     <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">destroy</span>
161:       <span class="ruby-identifier">clear</span>
162:       <span class="ruby-identifier">save</span>
163:     <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000130" class="method-detail">
        <a name="M000130"></a>

        <div class="method-heading">
          <a href="#M000130" class="method-signature">
          <span class="method-name">dirty?</span><span class="method-args">()</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Returns true if there are changes that need to be saved.
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000130-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000130-source">
<pre>
     <span class="ruby-comment cmt"># File vendor/plugins/paperclip/lib/paperclip/attachment.rb, line 136</span>
136:     <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">dirty?</span>
137:       <span class="ruby-ivar">@dirty</span>
138:     <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000129" class="method-detail">
        <a name="M000129"></a>

        <div class="method-heading">
          <a href="#M000129" class="method-signature">
          <span class="method-name">errors</span><span class="method-args">()</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Returns an array containing the <a
href="Attachment.html#M000129">errors</a> on this attachment.
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000129-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000129-source">
<pre>
     <span class="ruby-comment cmt"># File vendor/plugins/paperclip/lib/paperclip/attachment.rb, line 131</span>
131:     <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">errors</span>
132:       <span class="ruby-ivar">@errors</span>
133:     <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000140" class="method-detail">
        <a name="M000140"></a>

        <div class="method-heading">
          <a href="#M000140" class="method-signature">
          <span class="method-name">file?</span><span class="method-args">()</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Returns true if a file has been assigned.
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000140-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000140-source">
<pre>
     <span class="ruby-comment cmt"># File vendor/plugins/paperclip/lib/paperclip/attachment.rb, line 225</span>
225:     <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">file?</span>
226:       <span class="ruby-operator">!</span><span class="ruby-identifier">original_filename</span>.<span class="ruby-identifier">blank?</span>
227:     <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000142" class="method-detail">
        <a name="M000142"></a>

        <div class="method-heading">
          <a href="#M000142" class="method-signature">
          <span class="method-name">instance_read</span><span class="method-args">(attr)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Reads the attachment-specific attribute on the instance. See <a
href="Attachment.html#M000141">instance_write</a> for more details.
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000142-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000142-source">
<pre>
     <span class="ruby-comment cmt"># File vendor/plugins/paperclip/lib/paperclip/attachment.rb, line 241</span>
241:     <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">instance_read</span>(<span class="ruby-identifier">attr</span>)
242:       <span class="ruby-identifier">getter</span> = <span class="ruby-node">&quot;#{name}_#{attr}&quot;</span><span class="ruby-node">&quot;#{name}_#{attr}&quot;</span>
243:       <span class="ruby-identifier">responds</span> = <span class="ruby-identifier">instance</span>.<span class="ruby-identifier">respond_to?</span>(<span class="ruby-identifier">getter</span>)
244:       <span class="ruby-identifier">cached</span> = <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">instance_variable_get</span>(<span class="ruby-node">&quot;@_#{getter}&quot;</span>)
245:       <span class="ruby-keyword kw">return</span> <span class="ruby-identifier">cached</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">cached</span>
246:       <span class="ruby-identifier">instance</span>.<span class="ruby-identifier">send</span>(<span class="ruby-identifier">getter</span>) <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">responds</span> <span class="ruby-operator">||</span> <span class="ruby-identifier">attr</span>.<span class="ruby-identifier">to_s</span> <span class="ruby-operator">==</span> <span class="ruby-value str">&quot;file_name&quot;</span>
247:     <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000141" class="method-detail">
        <a name="M000141"></a>

        <div class="method-heading">
          <a href="#M000141" class="method-signature">
          <span class="method-name">instance_write</span><span class="method-args">(attr, value)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Writes the attachment-specific attribute on the instance. For example, <a
href="Attachment.html#M000141">instance_write</a>(:file_name,
&quot;me.jpg&quot;) will write &quot;me.jpg&quot; to the instance&#8216;s
&quot;avatar_file_name&quot; field (assuming the attachment is called
avatar).
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000141-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000141-source">
<pre>
     <span class="ruby-comment cmt"># File vendor/plugins/paperclip/lib/paperclip/attachment.rb, line 232</span>
232:     <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">instance_write</span>(<span class="ruby-identifier">attr</span>, <span class="ruby-identifier">value</span>)
233:       <span class="ruby-identifier">setter</span> = <span class="ruby-node">&quot;#{name}_#{attr}=&quot;</span><span class="ruby-node">&quot;#{name}_#{attr}=&quot;</span>
234:       <span class="ruby-identifier">responds</span> = <span class="ruby-identifier">instance</span>.<span class="ruby-identifier">respond_to?</span>(<span class="ruby-identifier">setter</span>)
235:       <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">instance_variable_set</span>(<span class="ruby-node">&quot;@_#{setter.to_s.chop}&quot;</span>, <span class="ruby-identifier">value</span>)
236:       <span class="ruby-identifier">instance</span>.<span class="ruby-identifier">send</span>(<span class="ruby-identifier">setter</span>, <span class="ruby-identifier">value</span>) <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">responds</span> <span class="ruby-operator">||</span> <span class="ruby-identifier">attr</span>.<span class="ruby-identifier">to_s</span> <span class="ruby-operator">==</span> <span class="ruby-value str">&quot;file_name&quot;</span>
237:     <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000134" class="method-detail">
        <a name="M000134"></a>

        <div class="method-heading">
          <a href="#M000134" class="method-signature">
          <span class="method-name">original_filename</span><span class="method-args">()</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Returns the name of the file as originally assigned, and lives in the
&lt;attachment&gt;_file_name attribute of the model.
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000134-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000134-source">
<pre>
     <span class="ruby-comment cmt"># File vendor/plugins/paperclip/lib/paperclip/attachment.rb, line 167</span>
167:     <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">original_filename</span>
168:       <span class="ruby-identifier">instance_read</span>(<span class="ruby-identifier">:file_name</span>)
169:     <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000127" class="method-detail">
        <a name="M000127"></a>

        <div class="method-heading">
          <a href="#M000127" class="method-signature">
          <span class="method-name">path</span><span class="method-args">(style_name = default_style)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Returns the <a href="Attachment.html#M000127">path</a> of the attachment as
defined by the :<a href="Attachment.html#M000127">path</a> option. If the
file is stored in the filesystem the <a
href="Attachment.html#M000127">path</a> refers to the <a
href="Attachment.html#M000127">path</a> of the file on disk. If the file is
stored in S3, the <a href="Attachment.html#M000127">path</a> is the
&quot;key&quot; part of the URL, and the :bucket option refers to the S3
bucket.
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000127-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000127-source">
<pre>
     <span class="ruby-comment cmt"># File vendor/plugins/paperclip/lib/paperclip/attachment.rb, line 121</span>
121:     <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">path</span> <span class="ruby-identifier">style_name</span> = <span class="ruby-identifier">default_style</span>
122:       <span class="ruby-identifier">original_filename</span>.<span class="ruby-identifier">nil?</span> <span class="ruby-value">? </span><span class="ruby-keyword kw">nil</span> <span class="ruby-operator">:</span> <span class="ruby-identifier">interpolate</span>(<span class="ruby-ivar">@path</span>, <span class="ruby-identifier">style_name</span>)
123:     <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000124" class="method-detail">
        <a name="M000124"></a>

        <div class="method-heading">
          <a href="#M000124" class="method-signature">
          <span class="method-name">processors</span><span class="method-args">()</span>
          </a>
        </div>
      
        <div class="method-description">
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000124-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000124-source">
<pre>
    <span class="ruby-comment cmt"># File vendor/plugins/paperclip/lib/paperclip/attachment.rb, line 64</span>
64:     <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">processors</span>
65:       <span class="ruby-ivar">@processors</span>.<span class="ruby-identifier">respond_to?</span>(<span class="ruby-identifier">:call</span>) <span class="ruby-operator">?</span> <span class="ruby-ivar">@processors</span>.<span class="ruby-identifier">call</span>(<span class="ruby-identifier">instance</span>) <span class="ruby-operator">:</span> <span class="ruby-ivar">@processors</span>
66:     <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000139" class="method-detail">
        <a name="M000139"></a>

        <div class="method-heading">
          <a href="#M000139" class="method-signature">
          <span class="method-name">reprocess!</span><span class="method-args">()</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
This method really shouldn&#8216;t be called that often. It&#8216;s
expected use is in the paperclip:refresh rake task and that&#8216;s it. It
will regenerate all thumbnails forcefully, by reobtaining the original file
and going through the post-process again.
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000139-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000139-source">
<pre>
     <span class="ruby-comment cmt"># File vendor/plugins/paperclip/lib/paperclip/attachment.rb, line 206</span>
206:     <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">reprocess!</span>
207:       <span class="ruby-identifier">new_original</span> = <span class="ruby-constant">Tempfile</span>.<span class="ruby-identifier">new</span>(<span class="ruby-value str">&quot;paperclip-reprocess&quot;</span>)
208:       <span class="ruby-identifier">new_original</span>.<span class="ruby-identifier">binmode</span>
209:       <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">old_original</span> = <span class="ruby-identifier">to_file</span>(<span class="ruby-identifier">:original</span>)
210:         <span class="ruby-identifier">new_original</span>.<span class="ruby-identifier">write</span>( <span class="ruby-identifier">old_original</span>.<span class="ruby-identifier">read</span> )
211:         <span class="ruby-identifier">new_original</span>.<span class="ruby-identifier">rewind</span>
212: 
213:         <span class="ruby-ivar">@queued_for_write</span> = { <span class="ruby-identifier">:original</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">new_original</span> }
214:         <span class="ruby-identifier">post_process</span>
215: 
216:         <span class="ruby-identifier">old_original</span>.<span class="ruby-identifier">close</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">old_original</span>.<span class="ruby-identifier">respond_to?</span>(<span class="ruby-identifier">:close</span>)
217: 
218:         <span class="ruby-identifier">save</span>
219:       <span class="ruby-keyword kw">else</span>
220:         <span class="ruby-keyword kw">true</span>
221:       <span class="ruby-keyword kw">end</span>
222:     <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000131" class="method-detail">
        <a name="M000131"></a>

        <div class="method-heading">
          <a href="#M000131" class="method-signature">
          <span class="method-name">save</span><span class="method-args">()</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Saves the file, if there are no <a
href="Attachment.html#M000129">errors</a>. If there are, it flushes them to
the instance&#8216;s <a href="Attachment.html#M000129">errors</a> and
returns false, cancelling the <a href="Attachment.html#M000131">save</a>.
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000131-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000131-source">
<pre>
     <span class="ruby-comment cmt"># File vendor/plugins/paperclip/lib/paperclip/attachment.rb, line 142</span>
142:     <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">save</span>
143:       <span class="ruby-identifier">flush_deletes</span>
144:       <span class="ruby-identifier">flush_writes</span>
145:       <span class="ruby-ivar">@dirty</span> = <span class="ruby-keyword kw">false</span>
146:       <span class="ruby-keyword kw">true</span>
147:     <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000135" class="method-detail">
        <a name="M000135"></a>

        <div class="method-heading">
          <a href="#M000135" class="method-signature">
          <span class="method-name">size</span><span class="method-args">()</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Returns the <a href="Attachment.html#M000135">size</a> of the file as
originally assigned, and lives in the &lt;attachment&gt;_file_size
attribute of the model.
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000135-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000135-source">
<pre>
     <span class="ruby-comment cmt"># File vendor/plugins/paperclip/lib/paperclip/attachment.rb, line 173</span>
173:     <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">size</span>
174:       <span class="ruby-identifier">instance_read</span>(<span class="ruby-identifier">:file_size</span>) <span class="ruby-operator">||</span> (<span class="ruby-ivar">@queued_for_write</span>[<span class="ruby-identifier">:original</span>] <span class="ruby-operator">&amp;&amp;</span> <span class="ruby-ivar">@queued_for_write</span>[<span class="ruby-identifier">:original</span>].<span class="ruby-identifier">size</span>)
175:     <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000123" class="method-detail">
        <a name="M000123"></a>

        <div class="method-heading">
          <a href="#M000123" class="method-signature">
          <span class="method-name">styles</span><span class="method-args">()</span>
          </a>
        </div>
      
        <div class="method-description">
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000123-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000123-source">
<pre>
    <span class="ruby-comment cmt"># File vendor/plugins/paperclip/lib/paperclip/attachment.rb, line 54</span>
54:     <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">styles</span>
55:       <span class="ruby-keyword kw">unless</span> <span class="ruby-ivar">@normalized_styles</span>
56:         <span class="ruby-ivar">@normalized_styles</span> = {}
57:         (<span class="ruby-ivar">@styles</span>.<span class="ruby-identifier">respond_to?</span>(<span class="ruby-identifier">:call</span>) <span class="ruby-operator">?</span> <span class="ruby-ivar">@styles</span>.<span class="ruby-identifier">call</span>(<span class="ruby-keyword kw">self</span>) <span class="ruby-operator">:</span> <span class="ruby-ivar">@styles</span>).<span class="ruby-identifier">each</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">name</span>, <span class="ruby-identifier">args</span><span class="ruby-operator">|</span>
58:           <span class="ruby-ivar">@normalized_styles</span>[<span class="ruby-identifier">name</span>] = <span class="ruby-constant">Paperclip</span><span class="ruby-operator">::</span><span class="ruby-constant">Style</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">name</span>, <span class="ruby-identifier">args</span>, <span class="ruby-keyword kw">self</span>)
59:         <span class="ruby-keyword kw">end</span>
60:       <span class="ruby-keyword kw">end</span>
61:       <span class="ruby-ivar">@normalized_styles</span>
62:     <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000128" class="method-detail">
        <a name="M000128"></a>

        <div class="method-heading">
          <a href="#M000128" class="method-signature">
          <span class="method-name">to_s</span><span class="method-args">(style_name = nil)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Alias to <tt><a href="Attachment.html#M000126">url</a></tt>
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000128-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000128-source">
<pre>
     <span class="ruby-comment cmt"># File vendor/plugins/paperclip/lib/paperclip/attachment.rb, line 126</span>
126:     <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">to_s</span> <span class="ruby-identifier">style_name</span> = <span class="ruby-keyword kw">nil</span>
127:       <span class="ruby-identifier">url</span>(<span class="ruby-identifier">style_name</span>)
128:     <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000137" class="method-detail">
        <a name="M000137"></a>

        <div class="method-heading">
          <a href="#M000137" class="method-signature">
          <span class="method-name">updated_at</span><span class="method-args">()</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Returns the last modified time of the file as originally assigned, and
lives in the &lt;attachment&gt;_updated_at attribute of the model.
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000137-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000137-source">
<pre>
     <span class="ruby-comment cmt"># File vendor/plugins/paperclip/lib/paperclip/attachment.rb, line 185</span>
185:     <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">updated_at</span>
186:       <span class="ruby-identifier">time</span> = <span class="ruby-identifier">instance_read</span>(<span class="ruby-identifier">:updated_at</span>)
187:       <span class="ruby-identifier">time</span> <span class="ruby-operator">&amp;&amp;</span> <span class="ruby-identifier">time</span>.<span class="ruby-identifier">to_f</span>.<span class="ruby-identifier">to_i</span>
188:     <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000126" class="method-detail">
        <a name="M000126"></a>

        <div class="method-heading">
          <a href="#M000126" class="method-signature">
          <span class="method-name">url</span><span class="method-args">(style_name = default_style, include_updated_timestamp = true)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Returns the public URL of the attachment, with a given style. Note that
this does not necessarily need to point to a file that your web server can
access and can point to an action in your app, if you need fine grained
security. This is not recommended if you don&#8216;t need the security,
however, for performance reasons. set include_updated_timestamp to false if
you want to stop the attachment update time appended to the <a
href="Attachment.html#M000126">url</a>
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000126-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000126-source">
<pre>
     <span class="ruby-comment cmt"># File vendor/plugins/paperclip/lib/paperclip/attachment.rb, line 112</span>
112:     <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">url</span> <span class="ruby-identifier">style_name</span> = <span class="ruby-identifier">default_style</span>, <span class="ruby-identifier">include_updated_timestamp</span> = <span class="ruby-keyword kw">true</span>
113:       <span class="ruby-identifier">url</span> = <span class="ruby-identifier">original_filename</span>.<span class="ruby-identifier">nil?</span> <span class="ruby-value">? </span><span class="ruby-identifier">interpolate</span>(<span class="ruby-ivar">@default_url</span>, <span class="ruby-identifier">style_name</span>) <span class="ruby-operator">:</span> <span class="ruby-identifier">interpolate</span>(<span class="ruby-ivar">@url</span>, <span class="ruby-identifier">style_name</span>)
114:       <span class="ruby-identifier">include_updated_timestamp</span> <span class="ruby-operator">&amp;&amp;</span> <span class="ruby-identifier">updated_at</span> <span class="ruby-value">? </span>[<span class="ruby-identifier">url</span>, <span class="ruby-identifier">updated_at</span>].<span class="ruby-identifier">compact</span>.<span class="ruby-identifier">join</span>(<span class="ruby-identifier">url</span>.<span class="ruby-identifier">include?</span>(<span class="ruby-value str">&quot;?&quot;</span>) <span class="ruby-operator">?</span> <span class="ruby-value str">&quot;&amp;&quot;</span> <span class="ruby-operator">:</span> <span class="ruby-value str">&quot;?&quot;</span>) <span class="ruby-operator">:</span> <span class="ruby-identifier">url</span>
115:     <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>


    </div>


  </div>


<div id="validator-badges">
  <p><small><a href="http://validator.w3.org/check/referer">[Validate]</a></small></p>
</div>

</body>
</html>